import RequestUtil from '@/utils/request.js';

const login = ({ username, password }) => {
  return RequestUtil.get('/login', {
    params: {
      username,
      password
    }
  });
};

const logout = () => {
  return RequestUtil.get('/logout');
};

const getLoginUser = () => {
  return RequestUtil.get('/getLoginUser');
};

const getUserList = (pageNo, pageSize, query) => {
  return RequestUtil.get('/user', {
    params: {
      pageNo,
      pageSize,
      ...query
    }
  });
};

const addUser = (user) => {
  return RequestUtil.post('/user', user);
};

const updateUser = (id, user) => {
  return RequestUtil.put('/user', {
    userId: id,
    ...user
  });
};

const deleteUser = (ids) => {
  return RequestUtil.delete(`/user/${ids.join(',')}`);
};

export const UserApi = {
  login,
  getLoginUser,
  logout,
  getUserList,
  addUser,
  updateUser,
  deleteUser
};
